package org.cqut.framework.exception;

import org.cqut.framework.web.response.ResultInfo;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * @author XiAoXu
 * @date 2021/5/26 15:47
 * @description
 */
@RestControllerAdvice
public class GlobalException {
    //需要拦截的异常
    @ExceptionHandler(Exception.class)
    public ResultInfo handleException(HttpServletRequest request, Exception ex) {
        //判断异常信息
        if (ex instanceof RuntimeException) {
            ex.printStackTrace();
            return new ResultInfo(4444, "运行时异常");
        }
        //将异常信息返回给前端
        return null;
    }
}
